﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _04AppDomainAndThread1
{
    class Program
    {
        static void Main(string[] args)
        {
            AppDomain DomainA;
            DomainA = AppDomain.CreateDomain("MyDomainA");
            string StringA = "DomainA Value";
            DomainA.SetData("DomainKey", StringA);
            CommonCallBack();
            CrossAppDomainDelegate delegateA = new CrossAppDomainDelegate(CommonCallBack);
            //CrossAppDomainDelegate委托：由 DoCallBack 用于跨应用程序域调用。
            DomainA.DoCallBack(delegateA); //在另一个应用程序域中执行代码
            Console.ReadKey();
        }
        public static void CommonCallBack()
        {
            AppDomain Domain;
            Domain = AppDomain.CurrentDomain;
            Console.WriteLine("The value'" + Domain.GetData("DomainKey") + "'was found in " + Domain.FriendlyName.ToString() + "  running on thread id:" + AppDomain.GetCurrentThreadId().ToString());

        } 
    }
}
